package com.hutu;

/**
 * 509. 斐波那契数
 * https://leetcode-cn.com/problems/fibonacci-number/
 *
 * @author hutu
 * @date 2020/12/17 10:52 上午
 */
public class Fib {

    public static int fib(int n) {
        if (n == 0) {
            return 0;
        }
        if (n == 1) {
            return 1;
        }
        int cur = 0;
        int next = 1;
        int sum = 0;
        for (int i = 2; i <= n; i++) {
            sum = cur + next;
            cur = next;
            next = sum;
        }
        return sum;
    }

    public static void main(String[] args) {
        System.out.println(fib(5));
    }
}
